package com.doit.day02;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;

public class MyIterator implements Iterator<Hero> {
    private String line = null;
    private BufferedReader br ;
    public MyIterator() throws Exception {
        //先吧文件中的数据取出来再说
        br = new BufferedReader(new FileReader("data/input/sanguo.txt"));
    }
    /*
         判断下一行还有没有数据
         */
    @Override
    public boolean hasNext() {
        try {
            line = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return line != null;
    }
    /**
     * 如果上面的方法返回true
     * 就取值
     */
    @Override
    public Hero next() {
        //张飞:60_120,蜀国
        String[] arr = line.split(":");
        //60_120,蜀国
        String[] arr1 = arr[1].split("_");
        //120,蜀国
        String[] arr2 = arr1[1].split(",");
        return new Hero(arr[0],Double.parseDouble(arr1[0]),Double.parseDouble(arr2[0]),arr2[1]);
    }
}
